from db.dbUtils import MysqlPool


def get_courses_by_teacher_name(name):
    with MysqlPool() as pool:
        c = pool.cursor
        sql = "select * from se_course where teacher='{}'".format(name)
        c.execute(sql)
        return c.fetchall()


def get_course_classes_by_coruse_id(code):
    with MysqlPool() as pool:
        c = pool.cursor
        sql = "select * from se_course_class where course_id='{}'".format(code)
        c.execute(sql)
        return c.fetchall()


def get_students_by_class_id(class_id):
    with MysqlPool() as pool:
        c = pool.cursor
        sql = "select * from se_user where u_c_id='{}'".format(class_id)
        c.execute(sql)
        return c.fetchall()


def get_major_id_by_major_name(m_name):
    with MysqlPool() as pool:
        c = pool.cursor
        sql = "select * from se_major where m_name='{}'".format(m_name)
        c.execute(sql)
        r = c.fetchall()
        if r:
            return r[0]
        return None


def get_course_by_course_id(course_id):
    sql = """
    select * from `se_course` where `code`='{}'
    """.format(course_id)
    with MysqlPool() as pool:
        c = pool.cursor
        c.execute(sql)
        return c.fetchall()
